# Maintainer: Natanael Copa <ncopa@alpinelinux.org>

_luaversions="5.1 5.2 5.3 5.4"

pkgname=lua-augeas
pkgver=0.1.2
pkgrel=7
pkgdesc="Lua bindings for Augeas"
url="https://git-old.alpinelinux.org/hosted/lua-augeas/"
arch="all"
license="MIT"
makedepends="augeas-dev"
for _i in $_luaversions; do
	makedepends="$makedepends lua$_i-dev"
	subpackages="$subpackages lua$_i-augeas:split_${_i/./_}"
done
source="https://dev.alpinelinux.org/archive/lua-augeas/lua-augeas-$pkgver.tar.bz2
	0001-support-for-Lua-5.2.patch"
options="!check"

prepare() {
	default_prepare
	for _i in $_luaversions; do
		cp -r "$builddir" "$srcdir"/build-$_i
	done
}

build() {
	for _i in $_luaversions; do
		cd "$srcdir"/build-$_i
		make LUAPC=lua$_i
	done
}

package() {
	for _i in $_luaversions; do
		install -D "$srcdir"/build-$_i/augeas.so \
			"$pkgdir"/usr/lib/lua/$_i/augeas.so
	done
}

_split() {
	local d= _ver=$1
	pkgdesc="Lua $_i bindings for Augeas"
	replaces="$pkgname"
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	depends=
	for d in usr/lib/lua usr/share/lua; do
		if [ -d "$pkgdir"/$d/$_ver ]; then
			mkdir -p "$subpkgdir"/$d
			mv "$pkgdir"/$d/$_ver "$subpkgdir"/$d/
		fi
	done
}

split_5_1() { _split 5.1; }
split_5_2() { _split 5.2; }
split_5_3() { _split 5.3; }
split_5_4() { _split 5.4; }

sha512sums="3ccbb32d4d71a9d390e814084a91fc26d51f25d31a1ff3a1e9927c494d196fdbc3954ae763b18e3b6e938bba9090773e4ac5fdb93ebc6d3293dc6be351485459  lua-augeas-0.1.2.tar.bz2
35ce609c0f34d88b3cd3a2edc6b7bc4332de9b06ad9b57a2fcc54c655399ad8e426b224e064d86146ccc1258ae7cb58a33d6187e7d5f396888a1d5a61637c940  0001-support-for-Lua-5.2.patch"
